package processor

import (
	"context"
	"fmt"
	"gitee.com/go-mid/booter"
	"gitee.com/go-mid/booter/bootservice"
	"gitee.com/go-mid/infra/xlog"
	"gitee.com/xserv/goldrush/api"
)

type ProcHttp struct{}

func (m *ProcHttp) Init() error {
	fun := "ProcHttp.Init -->"

	xlog.Infof(context.Background(), "%s call", fun)
	return nil
}

func (m *ProcHttp) Driver() (string, interface{}) {
	var ctx = context.Background()
	serv := bootservice.NewHttpServer()
	//前置拦截器
	var pre []bootservice.HandlerFunc
	pre = append(pre, Auth()) // 鉴权
	//后置拦截器
	var post []bootservice.HandlerFunc

	api.RegisterDemoHttpServer(serv, pre, post)
	api.RegisterUsercenterHttpServer(serv, pre, post)

	port, _ := booter.GlobalServer.ConfigCenter(ctx).GetString(ctx, "serv", "port")
	if port == "" {
		port = "9999"
	}
	return fmt.Sprintf("0.0.0.0:%s", port), serv
}
